<template>
	<view>
		<my-header :title="title" :back="true"></my-header>
		<uni-card style="margin-top: 60px">
			<uni-section title="最新消息" type="line">
				<template v-slot:right>
					<view @tap="toActivity">更多></view>
				</template>
			</uni-section>		
			<view v-if="newsList.length" v-for="(item, index) in newsList">
				<uni-list-item v-if="item.type == 2"  @tap="itemDetail(item)" :title="item.title" />
				<uni-link v-else :href="item.content" showUnderLine="false">
					<uni-list-item :title="item.title" />
				</uni-link>	
			</view>	
			<view v-if="!newsList.length" class="noContent">
				没有相关内容
			</view>
		</uni-card>	
		<uni-card>
			<uni-section title="政策导览" type="line">
				<template v-slot:right>
					<view @tap="toGuide">更多></view>
				</template>
			</uni-section>
			<view v-if="policeList.length" v-for="(item,index) in policeList">
				<uni-list-item  @tap="itemDetail(item)" :title="item.projectName" :note="item.contact" />
			</view>	
			<view v-if="!policeList.length" class="noContent">
				没有相关内容
			</view>
		</uni-card>
		<uni-card style="margin-top: 0px">
			<uni-section title="招聘信息" type="line">
				<template v-slot:right>
					<view @tap="toRecuit">更多></view>
				</template>
			</uni-section>
			<view v-if="recruitList.length" class="list" v-for="(item, index) in recruitList">
				<uni-list-item  @tap="itemDetail(item)" :title="item.recruitPosition" :note="item.enterpriseName" :rightText="item.salary" />
			</view>
			<view v-if="!recruitList.length" class="noContent">
				没有相关内容
			</view>
		</uni-card>	
	</view>
</template>

<script>
	import MyHeader from '@/components/header.vue'
	export default {
		components: {
			MyHeader,
		},
		data() {
			return {
				title: '关键词搜索',				
				newsList: [],
				policeList: [],
				recruitList: [],
				value: '',
			}
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			console.log(option); 
			this.value = option.value
		},
		onShow() {
			this.getPolice()
			this.getActivity()
			this.getRecruit()
		},
		methods: {
			getPolice() {
				let query = {
					page: 1,
					projectName: this.value,
				}
				uni.request({
					url: '/sf_enterprise_service/business/anonpolicy/queryPage',
					method: 'GET',
					data: query,
					success: (res) => {		
						console.log(res, 'res??')
						if(res.data.data.list.length) {	
							this.policeList = res.data.data.list
							console.log(this.policeList, 'policeList')
						}
					},
				})
			},
			getActivity() {
				let query = {
					page: 1,
					title: this.value,
				}
				uni.request({
					url: '/sf_enterprise_service/business/anonnews/queryPage',
					method: 'GET',
					data: query,
					success: (res) => {		
						console.log(res, 'res??')
						if(res.data.data.list.length) {	
							this.newsList = res.data.data.list							
							console.log(this.newsList, 'newsList')
						}
					},
				})
			},
			getRecruit() {
				let query = {
					page: 1,
					recruitPosition: this.value,
				}
				uni.request({
					url: '/sf_enterprise_service/business/anonrecruit/queryPage',
					data: query,
					method: 'GET',					
					success: (res) => {		
						console.log(res, 'res??')
						if(res.data.data.list.length) {	
							this.recruitList = res.data.data.list
							console.log(this.recruitList, 'recruitList')
						}
					},
				})
			},
			toRecuit() {
				uni.navigateTo({
					url: '/pages/recruit/recruit'
				})
			},
			toGuide() {
				uni.navigateTo({
					url: '/pages/policeGuide/policeGuide'
				})
			},
			toActivity() {
				uni.navigateTo({
					url: '/pages/activity/activity'
				})
			},
		}
	}
</script>

<style scoped>
.noContent {
	text-align: center;
}
</style>
